#include "QuaternionTransform.h"
#include "math.h"

QuaternionTransform::QuaternionTransform(void):m_Axis(0,0,1),m_Angle(0)
{
}

QuaternionTransform::~QuaternionTransform(void)
{
}

void QuaternionTransform::ResetTransformParameters()
{
	m_Axis.SetValues(0,0,1);
	m_Angle=0;
	m_Changed=true;
}

void QuaternionTransform::RecalculateMatrix() const
{
	float angle = m_Angle / 2.0f;
	float qx = m_Axis.x * sin(angle);
	float qy = m_Axis.y * sin(angle);
	float qz = m_Axis.z * sin(angle);
	float qw = cos(angle);

	float qx2 = qx*qx;
	float qy2 = qy*qy;
	float qz2 = qz*qz;
	float qw2 = qw*qw;

	m_CompiledMatrix.SetRow(0, 1-2*qy2-2*qz2,2*qx*qy+2*qw*qz,2*qx*qz-2*qw*qy,0);
	m_CompiledMatrix.SetRow(1, 2*qx*qy-2*qw*qz,1-2*qx2-2*qz2,2*qy*qz+2*qw*qx,0);
	m_CompiledMatrix.SetRow(2, 2*qx*qz+2*qw*qy,2*qy*qz-2*qw*qx,1-2*qx2-2*qy2,0);
	m_CompiledMatrix.SetRow(3, 0,0,0,1);
}